package leetcode.tree;

/**
 * @author: Oliver
 * @time: 2022/3/23/15:53
 */
public class ByteTest {
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    private static Integer maxRes;

    public static int getMax(TreeNode node) {
        if (node == null) {
            return 0;
        }
        int left = getMax(node.left) + 1;
        int right = getMax(node.right) + 1;
        maxRes = Math.max(left + right, maxRes);
        return maxRes;
    }

    public static void main(String[] args) {
        TreeNode node1 = new TreeNode(1);
        TreeNode node2 = new TreeNode(2);
        TreeNode node3 = new TreeNode(3);
        TreeNode node4 = new TreeNode(4);
        TreeNode node5 = new TreeNode(5);
        TreeNode node6 = new TreeNode(6);
        node1.left = node2;
        node2.left = node3;
        node3.left = node5;
        node2.right = node4;
        node4.right = node6;
        maxRes = 0;
        System.out.println(getMax(node4));
        System.out.println(maxRes);
    }

}
